package com.sourcetrip.raw.model;

/**
 * @author: ZhouBert
 * @date: 2020/12/1
 * @description:
 */
public class MyRBNode<E> extends MyBinaryNode<E> {

	private int color;

	public MyRBNode(E element, MyBinaryNode<E> parent, int color) {
		super(element, parent);
		this.color = color;
	}

	public int getColor() {
		return color;
	}

	public void setColor(int color) {
		this.color = color;
	}

	/**
	 * constructor
	 *
	 * @param element
	 * @param parent
	 */
	public MyRBNode(E element, MyBinaryNode<E> parent) {
		super(element, parent);
	}


	/**
	 * 获取本节点的兄弟节点
	 *
	 * @return
	 */
	public MyBinaryNode<E> sibling() {
		if (isLeftChild()) {
			return parent.right;
		}
		if (isRightChild()) {
			return parent.left;
		}
		return null;
	}

	@Override
	public String toString() {
		return this.element.toString() + "(" + (color == Color.BLACK ? "B" : "R") + ")";
	}
}
